﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Configuration;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Management.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;

namespace EntLibContrib.Query.Configuration.Manageability
{
	/// <summary>
	/// Represents the configuration information for a
	/// <see cref="EntLibContrib.Query.Configuration.ParameterSetData"/> instance.
	/// </summary>
	/// <remarks>
	/// ParameterSetData do not have any properties of their own that are not collections of other configuration objects.
	/// Instances of <see cref="ParameterSetSetting"/> are still published for the sake of completeness.
	/// </remarks>
	/// <seealso cref="NamedConfigurationSetting"/>
	[ManagementEntity]
	public class ParameterSetSetting : NamedConfigurationSetting
	{
		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="ParameterSetSetting"/> class with a configuration element and the name of the policy.
    /// </summary>
    /// <param name="sourceElement">The configuration element for the policy.</param>
    /// <param name="name">The name of the policy</param>
		public ParameterSetSetting(ConfigurationElement sourceElement, string name)
			: base(sourceElement, name)
		{
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns an enumeration of the published <see cref="ParameterSetSetting"/> instances.
		/// </summary>
		/// <returns></returns>
		[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		[ManagementEnumerator]
		public static IEnumerable<ParameterSetSetting> GetInstances()
		{
			return GetInstances<ParameterSetSetting>();
		}

		/// <summary>
		/// Returns the <see cref="ParameterSetSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <param name="name">The name of the parameter set.</param>
		/// <returns>
		/// The published <see cref="ParameterSetSetting"/> instance specified by the values for
		/// the key properties, or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static ParameterSetSetting BindInstance(string applicationName,
																									string sectionName,
																									string name)
		{
			return BindInstance<ParameterSetSetting>(applicationName, sectionName, name);
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Saves the changes on the <see cref="ParameterSetSetting"/> to its corresponding configuration object.
		/// </summary>
		/// <param name="sourceElement">The configuration object on which the changes must be saved.</param>
		/// <returns>
		/// 	<see langword="true"/> if changes have been saved, <see langword="false"/> otherwise.
		/// </returns>
		/// <remarks>Must be overridden by subclasses to perform the actual save.</remarks>
		protected override bool SaveChanges(ConfigurationElement sourceElement)
		{
			// nothing to be saved
			return true;
		}
		#endregion
	}
}
